home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / ladybug.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  5KB  |  212 lines

  1. /***************************************************************************
  2.  
  3.   vidhrdw.c
  4.  
  5.   Functions to emulate the video hardware of the machine.
  6.  
  7. ***************************************************************************/
  8.  
  9. #include "driver.h"
  10. #include "vidhrdw/generic.h"
  11.  
  12.  
  13.  
  14. static int flipscreen;
  15.  
  16.  
  17.  
  18. /***************************************************************************
  19.  
  20.   Convert the color PROMs into a more useable format.
  21.  
  22.   Lady Bug has a 32 bytes palette PROM and a 32 bytes sprite color lookup
  23.   table PROM.
  24.   The palette PROM is connected to the RGB output this way:
  25.  
  26.   bit 7 -- inverter -- 220 ohm resistor  -- BLUE
  27.         -- inverter -- 220 ohm resistor  -- GREEN
  28.         -- inverter -- 220 ohm resistor  -- RED
  29.         -- inverter -- 470 ohm resistor  -- BLUE
  30.         -- unused
  31.         -- inverter -- 470 ohm resistor  -- GREEN
  32.         -- unused
  33.   bit 0 -- inverter -- 470 ohm resistor  -- RED
  34.  
  35. ***************************************************************************/
  36. void ladybug_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  37. {
  38.     int i;
  39.  
  40.  
  41.     for (i = 0;i < 32;i++)
  42.     {
  43.         int bit1,bit2;
  44.  
  45.  
  46.         bit1 = (~color_prom[i] >> 0) & 0x01;
  47.         bit2 = (~color_prom[i] >> 5) & 0x01;
  48.         palette[3*i] = 0x47 * bit1 + 0x97 * bit2;
  49.         bit1 = (~color_prom[i] >> 2) & 0x01;
  50.         bit2 = (~color_prom[i] >> 6) & 0x01;
  51.         palette[3*i + 1] = 0x47 * bit1 + 0x97 * bit2;
  52.         bit1 = (~color_prom[i] >> 4) & 0x01;
  53.         bit2 = (~color_prom[i] >> 7) & 0x01;
  54.         palette[3*i + 2] = 0x47 * bit1 + 0x97 * bit2;
  55.     }
  56.  
  57.     /* characters */
  58.     for (i = 0;i < 8;i++)
  59.     {
  60.         colortable[4 * i] = 0;
  61.         colortable[4 * i + 1] = i + 0x08;
  62.         colortable[4 * i + 2] = i + 0x10;
  63.         colortable[4 * i + 3] = i + 0x18;
  64.     }
  65.  
  66.     /* sprites */
  67.     for (i = 0;i < 4 * 8;i++)
  68.     {
  69.         int bit0,bit1,bit2,bit3;
  70.  
  71.  
  72.         /* low 4 bits are for sprite n */
  73.         bit0 = (color_prom[i + 32] >> 3) & 0x01;
  74.         bit1 = (color_prom[i + 32] >> 2) & 0x01;
  75.         bit2 = (color_prom[i + 32] >> 1) & 0x01;
  76.         bit3 = (color_prom[i + 32] >> 0) & 0x01;
  77.         colortable[i + 4 * 8] = 1 * bit0 + 2 * bit1 + 4 * bit2 + 8 * bit3;
  78.  
  79.         /* high 4 bits are for sprite n + 8 */
  80.         bit0 = (color_prom[i + 32] >> 7) & 0x01;
  81.         bit1 = (color_prom[i + 32] >> 6) & 0x01;
  82.         bit2 = (color_prom[i + 32] >> 5) & 0x01;
  83.         bit3 = (color_prom[i + 32] >> 4) & 0x01;
  84.         colortable[i + 4 * 16] = 1 * bit0 + 2 * bit1 + 4 * bit2 + 8 * bit3;
  85.     }
  86. }
  87.  
  88.  
  89.  
  90. WRITE_HANDLER( ladybug_flipscreen_w )
  91. {
  92.     if (flipscreen != (data & 1))
  93.     {
  94.         flipscreen = data & 1;
  95.         memset(dirtybuffer,1,videoram_size);
  96.     }
  97. }
  98.  
  99.  
  100.  
  101. /***************************************************************************
  102.  
  103.   Draw the game screen in the given osd_bitmap.
  104.   Do NOT call osd_update_display() from this function, it will be called by
  105.   the main emulation engine.
  106.  
  107. ***************************************************************************/
  108. void ladybug_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  109. {
  110.     int i,offs;
  111.  
  112.  
  113.     /* for every character in the Video RAM, check if it has been modified */
  114.     /* since last time and update it accordingly. */
  115.     for (offs = videoram_size - 1;offs >= 0;offs--)
  116.     {
  117.         if (dirtybuffer[offs])
  118.         {
  119.             int sx,sy;
  120.  
  121.  
  122.             dirtybuffer[offs] = 0;
  123.  
  124.             sx = offs % 32;
  125.             sy = offs / 32;
  126.  
  127.             if (flipscreen)
  128.             {
  129.                 sx = 31 - sx;
  130.                 sy = 31 - sy;
  131.             }
  132.  
  133.             drawgfx(tmpbitmap,Machine->gfx[0],
  134.                     videoram[offs] + 32 * (colorram[offs] & 8),
  135.                     colorram[offs],
  136.                     flipscreen,flipscreen,
  137.                     8*sx,8*sy,
  138.                     0,TRANSPARENCY_NONE,0);
  139.         }
  140.     }
  141.  
  142.  
  143.     /* copy the temporary bitmap to the screen */
  144.     {
  145.         int scroll[32];
  146.         int sx,sy;
  147.  
  148.  
  149.         for (offs = 0;offs < 32;offs++)
  150.         {
  151.             sx = offs % 4;
  152.             sy = offs / 4;
  153.  
  154.             if (flipscreen)
  155.                 scroll[31-offs] = -videoram[32 * sx + sy];
  156.             else
  157.                 scroll[offs] = -videoram[32 * sx + sy];
  158.         }
  159.  
  160.         copyscrollbitmap(bitmap,tmpbitmap,32,scroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  161.     }
  162.  
  163.  
  164.     /* Draw the sprites. Note that it is important to draw them exactly in this */
  165.     /* order, to have the correct priorities. */
  166.     /* sprites in the columns 15, 1 and 0 are outside of the visible area */
  167.     for (offs = spriteram_size - 2*0x40;offs >= 2*0x40;offs -= 0x40)
  168.     {
  169.         i = 0;
  170.         while (i < 0x40 && spriteram[offs + i] != 0)
  171.             i += 4;
  172.  
  173.         while (i > 0)
  174.         {
  175. /*
  176.  abccdddd eeeeeeee fffghhhh iiiiiiii
  177.  
  178.  a enable?
  179.  b size (0 = 8x8, 1 = 16x16)
  180.  cc flip
  181.  dddd y offset
  182.  eeeeeeee sprite code (shift right 2 bits for 16x16 sprites)
  183.  fff unknown
  184.  g sprite bank
  185.  hhhh color
  186.  iiiiiiii x position
  187. */
  188.             i -= 4;
  189.  
  190.             if (spriteram[offs + i] & 0x80)
  191.             {
  192.                 if (spriteram[offs + i] & 0x40)    /* 16x16 */
  193.                     drawgfx(bitmap,Machine->gfx[1],
  194.                             (spriteram[offs + i + 1] >> 2) + 4 * (spriteram[offs + i + 2] & 0x10),
  195.                             spriteram[offs + i + 2] & 0x0f,
  196.                             spriteram[offs + i] & 0x20,spriteram[offs + i] & 0x10,
  197.                             spriteram[offs + i + 3],
  198.                             offs / 4 - 8 + (spriteram[offs + i] & 0x0f),
  199.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  200.                 else    /* 8x8 */
  201.                     drawgfx(bitmap,Machine->gfx[2],
  202.                             spriteram[offs + i + 1] + 4 * (spriteram[offs + i + 2] & 0x10),
  203.                             spriteram[offs + i + 2] & 0x0f,
  204.                             spriteram[offs + i] & 0x20,spriteram[offs + i] & 0x10,
  205.                             spriteram[offs + i + 3],
  206.                             offs / 4 + (spriteram[offs + i] & 0x0f),
  207.                             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  208.             }
  209.         }
  210.     }
  211. }
  212.